const express = require('express')
const router = express.Router()
const db = require('../../connection/Connection')
const jwt = require('jsonwebtoken')
const SECRET = 'asdfta219*&%^jWJSHFJ'


router.post('/getProjectEmployeesInfo', async (req, res) => {
    const result = jwt.verify(req.body.token, SECRET)
    let sql = 'select departmentId from user_role where username = ?'
    db.base(sql, result.username, response_temp => {
        //验证用户对应角色的权限
        console.log(response_temp)
        if(response_temp!=null&& response_temp.length > 0) {
            sql = 'SELECT `name` FROM employees WHERE current_task = ?'
            //查找对应员工
            db.base(sql,req.body.projectId, response => {
                console.log(response)
                let data = ""
                for(i = 0;i<response.length;i++){
                    data = data + "/"+response[i].name
                }
                res.json({
                    data:data
                })
            })
        }
    })
})

module.exports = router
